package com.example.fw;

import org.openqa.selenium.By;
import com.example.tests.GroupObject;

public class GroupHelper extends HelperWithWebDriverBase {

	public GroupHelper(ApplicationManager manager) {
		super (manager);
	}

	public void createGroup(GroupObject groupObject) {
		manager.getNavigationHelper().goToListPage();
		initGroupCreation();
		fillGroupForm(groupObject);
		submitGroupCreation();
		manager.getNavigationHelper().returnToGroupListPage();
	}
	
	public void deleteGroup(int i) {
		manager.getNavigationHelper().goToListPage();
		checkGroup(i);
		click(By.name("delete"));
		manager.getNavigationHelper().returnToGroupListPage();
	}


	public void modifyGroup(int i, GroupObject groupObject) {
		manager.getNavigationHelper().goToListPage();
		initGroupModification(i);
		fillGroupForm(groupObject);
		submitGroupModification();
		manager.getNavigationHelper().returnToGroupListPage();
	}

	private void initGroupModification(int i) {
		checkGroup(i);
		click(By.name("edit"));
	}

	private void initGroupCreation() {
		click(By.name("new"));
	}

	private void checkGroup(int i) {
		click(By.name("selected[]"));
	}
	
	private void fillGroupForm(GroupObject groupObject) {
		type(By.name("group_name"), groupObject.name);
		type(By.name("group_header"), groupObject.header);
		type(By.name("group_footer"), groupObject.footer);
	}
	
	private void submitGroupCreation() {
		click(By.name("submit"));
	}
	
	private void submitGroupModification() {
		click(By.name("update"));
		
	}
	

}
